package com.zzptc.easyshop.dao;

import com.zzptc.easyshop.db.IDB;
import com.zzptc.easyshop.db.MysqlDB;
import com.zzptc.easyshop.vo.Users;
import com.zzptc.easyshop.vo.VO;

import javax.persistence.SqlResultSetMapping;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

public class UserDao implements IDAO {
    public boolean insert(VO vo) throws SQLException {
        //获取数据库的连接
        IDB db=new MysqlDB();
        Connection conn=db.getConnnection();
        //用工具操作数据库
        PreparedStatement ps=conn.prepareStatement("insert into t_easybuy_user (eu_user_id,eu_user_name,eu_password)values(?,?,?)");
        //注入值
        Users users=(Users)vo;
        ps.setString(1,users.getEu_user_id());
        ps.setString(2,users.getEu_user_name());
        ps.setString(3,users.getEu_password());
        //操作数据库
        int i=ps.executeUpdate();
        ps.close();
        db.closeConn();
        return i>0;
    }
    @Override
    public List getAll() throws SQLException{
        return null;
    }

    @Override
    public boolean deleteByID(VO vo)throws SQLException {
        return false;
    }

    @Override
    public boolean update(VO vo)throws SQLException {
        return false;
    }
    @Override
    public VO getByID(VO vo)throws SQLException{
        return null;
    }

    @Override
    public boolean login(Users user) {
        return false;
    }

    public static void main(String[] args) {
        UserDao u=new UserDao();
        Users user=new Users();
        user.setEu_user_id("3");
        user.setEu_user_name("YO");
        user.setEu_password("root");
        try {
            if( u.insert(user)){
                System.out.println("succ");
            }else{
                System.out.println("error");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
